<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>代码生成维护</title>
    <script src="../../../resources/app/all.js" type="text/javascript"></script>
    <style type="text/css">
        a:link {
            text-decoration: none;
        }

        a:visited {
            text-decoration: none;
        }

        a:hover {
            text-decoration: none;
        }

        a:active {
            text-decoration: none;
        }


        .layui-table-cell, .layui-table-tool-panel li {
            overflow: visible !important;
        }

        .layui-form-select .layui-input {
            height: 30px;
        }

        .layui-table-box {
            overflow: visible !important;
        }

        .layui-table-body {
            overflow: visible !important;
        }

    </style>

</head>
<body class="easyui-layout" data-options="fit:true">

<div data-options="region:'center'" style="padding: 5px;">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li>基本信息</li>
            <li class="layui-this">字段信息</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane" action="" id="generatorTableForm"
                      lay-filter="generatorTableExample">
                    <div class="layui-form-item">
                        <label class="layui-form-label">表名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="id" name="id">
                            <input type="text" name="tableName" lay-verify="required" disabled="disabled"
                                   autocomplete="off" placeholder="请输入用户名"
                                   class="layui-input layui-disabled">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">表描述</label>
                        <div class="layui-input-block">
                            <input type="text" name="tableComment" lay-verify="required" disabled="disabled"
                                   autocomplete="off" placeholder="请输入用户名"
                                   class="layui-input layui-disabled">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">实体名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="className" lay-verify="required" disabled="disabled"
                                   autocomplete="off" placeholder="请输入用户名"
                                   class="layui-input layui-disabled">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">包名</label>
                        <div class="layui-input-block">
                            <input type="text" name="packageName" lay-verify="required" autocomplete="off"
                                   placeholder="请输入用户名"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">模块</label>
                        <div class="layui-input-block">
                            <input type="text" name="moduleName" lay-verify="required" autocomplete="off"
                                   placeholder="请输入用户名"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">业务</label>
                        <div class="layui-input-block">
                            <input type="text" name="businessName" lay-verify="required" autocomplete="off"
                                   placeholder="请输入用户名"
                                   class="layui-input">
                        </div>
                    </div>

                </form>

            </div>
            <div class="layui-tab-item layui-show">
                <table class="layui-hide" id="genFieldTable" lay-filter="genFieldTable"></table>
            </div>
        </div>
    </div>


</div>
<div data-options="region:'south',border:false">
    <div class="dialog-button">
        <button id="generatorSave" class="layui-btn layui-btn-normal">确定</button>
        <button id="generatorCancel" class="layui-btn layui-btn-primary">取消</button>
    </div>
</div>

<script type="text/html" id="isRequired">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="isRequired" value="{{d.id}}" lay-skin="primary" lay-filter="lockDemo" {{
           d.isRequired== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="isInsert">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="isInsert" value="{{d.id}}" lay-skin="primary" lay-filter="lockDemo" {{
           d.isInsert== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="isEdit">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="isEdit" value="{{d.id}}" lay-skin="primary" lay-filter="lockDemo" {{
           d.isEdit== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="isList">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="isList" value="{{d.id}}" lay-skin="primary" lay-filter="lockDemo" {{
           d.isList== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="isQuery">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="isQuery" value="{{d.id}}" lay-skin="primary" lay-filter="lockDemo" {{
           d.isQuery== 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="selectTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <select name="{{d.id}}"  lay-filter="select" >
        <option value="input" {{d.htmlType=='input' ?
        'selected' : '' }}>文本框</option>
        <option value="textarea" {{d.htmlType=='textarea' ?
        'selected' : '' }}>文本域</option>
        <option value="radio" {{d.htmlType=='radio' ?
        'selected' : '' }}>单选框</option>
        <option value="checkbox" {{d.htmlType=='checkbox' ?
        'selected' : '' }}>复选框</option>
        <option value="date" {{d.htmlType=='date' ?
        'selected' : '' }}>时间组件</option>
        <option value="richtext" {{d.htmlType=='richtext' ?
        'selected' : '' }}>富文本</option>
    </select>
</script>


<script>
    layui.use(['form', 'table', 'element'], function () {
        var form = layui.form
            , layer = layui.layer
            , table = layui.table;
        let parData = ToolUtil.OpenData();
        var data = parData.data;
        form.val('generatorTableExample', JSON.parse(JSON.stringify(data)));

        table.render({
            elem: '#genFieldTable',
            data: JSON.parse(JSON.stringify(data.columns)),
            title: '代码列表',
            cellMinWidth: 80,
            cols: [[
                {field: 'id', type: 'numbers', width: 80, title: 'ID', sort: true},
                {field: 'columnName', title: '字段'},
                {field: 'columnComment', title: '字段描述'},
                {field: 'columnType', title: '物理类型'},
                {field: 'javaType', title: '实体类型'},
                {field: 'javaField', title: '实体属性'},
                {field: 'isRequired', width: 50, title: '必填', templet: '#isRequired', unresize: true},
                {field: 'isInsert', width: 50, title: '插入', templet: '#isInsert', unresize: true},
                {field: 'isEdit', width: 50, title: '编辑', templet: '#isEdit', unresize: true},
                {field: 'isList', width: 50, title: '列表', templet: '#isList', unresize: true},
                {field: 'isQuery', width: 50, title: '查询', templet: '#isQuery', unresize: true},
                {field: 'htmlType', width: 200, title: '显示类型', templet: '#selectTpl', unresize: true},
                {field: 'dictType', title: '字典类型'},
            ]],
            page:false,
            limit:Number.MAX_VALUE,
            done: function (res, curr, count) {
                layer.closeAll('loading');
            }
        });

        form.on('select(select)',function (obj) {
            let data = table.cache.genFieldTable;
            for (let i = 0; i < data.length; i++) {
                if (data[i].id+"" == obj.elem.name) {
                    data[i].htmlType =obj.value;
                    break;
                }
            }
            table.reload('genFieldTable', {
                data: data
            });
        });

        //监听锁定操作
        form.on('checkbox(lockDemo)', function (obj) {
            let data = table.cache.genFieldTable;
            for (let i = 0; i < data.length; i++) {
                if (data[i].id+"" == this.value) {
                    if (this.name == 'isRequired') {
                        data[i].isRequired = obj.elem.checked ? '1' : '0';
                    }
                    if (this.name == 'isInsert') {
                        data[i].isInsert = obj.elem.checked ? '1' : '0';
                    }
                    if (this.name == 'isEdit') {
                        data[i].isEdit = obj.elem.checked ? '1' : '0';
                    }
                    if (this.name == 'isList') {
                        data[i].isList = obj.elem.checked ? '1' : '0';
                    }
                    if (this.name == 'isQuery') {
                        data[i].isQuery = obj.elem.checked ? '1' : '0';
                    }
                    break;
                }
            }
            table.reload('genFieldTable', {
                data: data
            });
        });

        layui.$('#generatorSave').on('click', function () {
            let data = ToolUtil.FormJSON("generatorTableForm");
            data.columns=table.cache.genFieldTable;
            ToolUtil.PUT({
                url: global.api_url + "/sys/generator",
                data: JSON.stringify(data),
                async: false,
                success: function (obj) {
                    if (obj && obj.code === '00') {
                        saveClear();
                    } else if (obj.code === '98' || obj.code === '97') {
                        location.href = global.loginUrl;
                    } else {
                        layer.alert(obj.msg,{icon:5});
                    }
                }
            });

        });
        layui.$('#generatorCancel').on('click', function () {
            clear();
        });

        function saveClear() {
            parent.location.reload();
            clear();
        }

        function clear() {
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            layer.close(index);
        }

    });
</script>
</body>
</html>